Scenario C - Peak Number Variation

In this scenario the number of peaks in a generated dataset is varied in from 2 to 4, the rest of the parameters is kept constant (noise level = 1%). The number of peaks expected by the probabilistic model is varied between the low and high peak number.

The model used in the inference of the parameters is formulated as follows:

\begin{equation} \large y = f(x) = \sum\limits_{m=1}^M \big[A_m \cdot e^{-\frac{(x-\mu_m)^2}{2\cdot\sigma_m^2}}\big] + \epsilon \end{equation}
In [1]:
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pymc3 as pm
import arviz as az

#az.style.use('arviz-darkgrid')

print('Running on PyMC3 v{}'.format(pm.__version__))
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Running on PyMC3 v3.8

Import local modules

In [2]:
import os
import sys
sys.path.append('../../modules')
import datagen as dg
import models as mdl
import results as res
import figures as fig
import settings as cnf

Local configuration

In [3]:
# output for results and images
out_path      = './output_adapt_diag'
file_basename = out_path + '/scenario_peaks'
        
# if dir does not exist, create it
if not os.path.exists(out_path):
    os.makedirs(out_path)

conf = {}
    
# scenario name
conf['scenario'] = 'peak variation'
    
# initialization method for sampler
conf['init_mode'] = 'adapt_diag'

# probabilistic model (priors)
conf['prior_model'] = 'lognormal'

# provide peak positions to the model as testvalues ('yes'/'no')
conf['peak_info'] = 'yes'

# model mode ('train'/eval')
conf['model_mode'] = 'train'

# data mode ('generate'/'preload')
conf['data_mode'] = 'generate'

# dataset directory (needed for 'preload' data mode)
#conf['dataset_dir'] = './input_datasets'

# number of cores to run sampling chains on
conf['ncores'] = 2

# number of samples per chain
conf['nsamples'] = 2000
In [4]:
conf
Out[4]:
{'scenario': 'peak variation',
 'init_mode': 'adapt_diag',
 'prior_model': 'lognormal',
 'peak_info': 'yes',
 'model_mode': 'train',
 'data_mode': 'generate',
 'ncores': 2,
 'nsamples': 2000}

Save configuration

In [5]:
cnf.save(out_path, conf)

Generate data and plot

In [6]:
# list of wavelengths (x-values)
xval = [i for i in range(200, 400, 2)]

ldata  = []
lpeaks = []
lpeakdata = []

# number of spectra per peak number
nsets  = 5

# number of peaks in the spectrum
peak_numbers = [2,3,4,5]

# total number of datasets
tsets = nsets * len(peak_numbers)
        
if conf['model_mode'] == 'train' and conf['data_mode'] == 'generate':
    # generate the datasets
    for pn in peak_numbers:
        for i in range(nsets):
            df, peaks, df_peakinfo = dg.data_generator(xvalues=xval, nsamples=15, npeaks=pn)
            ldata.append(df)
            lpeaks.append(peaks)
            lpeakdata.append(df_peakinfo)
    # save data and peak information to disk
    for i in range(len(ldata)):
        ldata[i].to_csv(out_path + '/dataset_%02d.csv' % (i+1), index=False)
        lpeakdata[i].to_csv(out_path + '/peakdata_%02d.csv' % (i+1), index=False)
    dg.data_save(out_path + '/peakinfo.csv', lpeaks)
        
elif conf['model_mode'] == 'train' and conf['data_mode'] == 'preload':           
    # load pre-generated datasets from disk
    ldata, lpeaks, lpeakdata = dg.data_load(tsets, conf['dataset_dir'])
    
else:        
    # load data from disk
    if conf['data_mode'] == 'preload':
        ldata, lpeaks, lpeakdata = dg.data_load(tsets, conf['dataset_dir'])
    else:
        ldata, lpeaks, lpeakdata = dg.data_load(tsets, out_path)
In [7]:
print("total number of peak numbers            : {0}".format(len(peak_numbers)))
print("total number of spectra per peak number : {0}".format(nsets))
print("total number of datasets per model      : {0}".format(tsets))
print("total number of inference runs          : {0}".format(nsets*len(peak_numbers)**2))
total number of peak numbers            : 4
total number of spectra per peak number : 5
total number of datasets per model      : 20
total number of inference runs          : 80
In [8]:
# plot datasets
fig.plot_datasets(ldata, lpeaks, dims=(int(tsets/2),2), figure_size=(12,int(tsets*(1.8))), 
                                                        savefig='yes', fname=file_basename)

Initialize models and run inference

In [9]:
# convert pandas data to numpy arrays
x_val = np.array(xval, dtype='float32')

# store dataset y-values in list
cols = ldata[0].columns
y_val = [ldata[i][cols].values for i in range(len(ldata))]
In [10]:
# initialize models and run inference
models = []
traces = []
lmodpeak = []

# actual run number
run = 1

# total number of inference runs
truns = nsets * len(peak_numbers)**2

for pn in peak_numbers:
    if conf['model_mode'] == 'train':
        # for each model (from low-high peak number) run inference on all spectra
        print("running {0}-peak model".format(pn))
    
    for i in range(len(ldata)):
        if conf['peak_info'] == 'yes':
            # Get the peak numbers from the list. If the actual peak number in the spectrum is 
            # lower than what the model is expecting, then expand the list to the expected size,
            # duplicating the existing peak mu values, else truncate the list (taking the peaks
            # with the highest amplitude).
            plist = sorted(lpeaks[i])
            if len(plist) < pn:
                pl = sorted(np.resize(plist, (1,pn)).flatten())
            else:
                # sort peak info dataframe on amplitude value 
                l1 = lpeakdata[i].sort_values('amp', ascending=False)
                # truncate list to expected peak number
                pl = l1['mu'].values[:pn]
                
            model_g = mdl.model_gauss(xvalues=x_val, observations=y_val[i], npeaks=pn, 
                                      mu_peaks=pl, pmodel=conf['prior_model'])
        else:
            model_g = mdl.model_gauss(xvalues=x_val, observations=y_val[i], npeaks=pn,
                                      pmodel=conf['prior_model'])      
        models.append(model_g)

        with model_g:
            if conf['model_mode'] == 'train':
                print("({2}/{3}) running inference on dataset #{0}/{1} [{4}-peak model:{5}-peak spectrum]"
                      .format(i+1,len(ldata),run,truns,pn,len(plist)))
                lmodpeak += [(pn,len(plist))]
                trace_g = pm.sample(conf['nsamples'], init=conf['init_mode'], cores=conf['ncores'])
                traces.append(trace_g)
                # save inference results
                pm.backends.text.dump(out_path + '/traces_%02d' % (run), trace_g)
            else:
                # load traces from disk
                print("loading dataset #{0}/{1}".format(run,truns))
                trace_g = pm.backends.text.load(out_path + '/traces_%02d' % (run))
                traces.append(trace_g)
            run += 1
running 2-peak model
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(1/80) running inference on dataset #1/20 [2-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 7 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 548.04draws/s] 
There were 5 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.8821710233973523, but should be close to 0.8. Try to increase the number of tuning steps.
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(2/80) running inference on dataset #2/20 [2-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 574.99draws/s]
The acceptance probability does not match the target. It is 0.890982542486199, but should be close to 0.8. Try to increase the number of tuning steps.
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9180753138400999, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(3/80) running inference on dataset #3/20 [2-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 7 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 584.34draws/s] 
There were 4 divergences after tuning. Increase `target_accept` or reparameterize.
There were 3 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(4/80) running inference on dataset #4/20 [2-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 558.83draws/s]
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9121851848008831, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.9143845700548372, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(5/80) running inference on dataset #5/20 [2-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 9 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 540.81draws/s]
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9145871029397724, but should be close to 0.8. Try to increase the number of tuning steps.
There were 7 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9135280952340452, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(6/80) running inference on dataset #6/20 [2-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [01:40<00:00, 49.86draws/s]
The acceptance probability does not match the target. It is 0.9993913949039933, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.9981086790326976, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(7/80) running inference on dataset #7/20 [2-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 611.94draws/s] 
The acceptance probability does not match the target. It is 0.8865467753809854, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.8940176912719464, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(8/80) running inference on dataset #8/20 [2-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 573.65draws/s]
The acceptance probability does not match the target. It is 0.9032277259429364, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(9/80) running inference on dataset #9/20 [2-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 3 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 579.36draws/s] 
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(10/80) running inference on dataset #10/20 [2-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 580.02draws/s] 
The acceptance probability does not match the target. It is 0.8967666830966682, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.8930583638777305, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(11/80) running inference on dataset #11/20 [2-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:07<00:00, 649.24draws/s] 
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(12/80) running inference on dataset #12/20 [2-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 545.73draws/s]
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(13/80) running inference on dataset #13/20 [2-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:07<00:00, 641.28draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(14/80) running inference on dataset #14/20 [2-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 586.73draws/s] 
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(15/80) running inference on dataset #15/20 [2-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 579.82draws/s]
The acceptance probability does not match the target. It is 0.9126674287894128, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.8832284531192329, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(16/80) running inference on dataset #16/20 [2-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 623.39draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(17/80) running inference on dataset #17/20 [2-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:07<00:00, 706.53draws/s] 
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(18/80) running inference on dataset #18/20 [2-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:07<00:00, 655.77draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(19/80) running inference on dataset #19/20 [2-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 937 divergences: 100%|██████████| 5000/5000 [00:37<00:00, 131.81draws/s]
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6476066002601646, but should be close to 0.8. Try to increase the number of tuning steps.
There were 936 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.10276309151757043, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.2 for some parameters.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(20/80) running inference on dataset #20/20 [2-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 589.59draws/s]
running 3-peak model
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(21/80) running inference on dataset #1/20 [3-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 315 divergences: 100%|██████████| 5000/5000 [01:08<00:00, 72.72draws/s] 
There were 295 divergences after tuning. Increase `target_accept` or reparameterize.
There were 19 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9126330343972656, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.2 for some parameters.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(22/80) running inference on dataset #2/20 [3-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 870 divergences: 100%|██████████| 5000/5000 [01:40<00:00, 49.83draws/s] 
There were 644 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.4614065304995416, but should be close to 0.8. Try to increase the number of tuning steps.
There were 226 divergences after tuning. Increase `target_accept` or reparameterize.
The rhat statistic is larger than 1.05 for some parameters. This indicates slight problems during sampling.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(23/80) running inference on dataset #3/20 [3-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 775 divergences: 100%|██████████| 5000/5000 [04:48<00:00, 17.33draws/s]
There were 247 divergences after tuning. Increase `target_accept` or reparameterize.
There were 528 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(24/80) running inference on dataset #4/20 [3-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 58 divergences: 100%|██████████| 5000/5000 [02:29<00:00, 33.44draws/s]
There were 48 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9091599608936819, but should be close to 0.8. Try to increase the number of tuning steps.
There were 10 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9595825277378982, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(25/80) running inference on dataset #5/20 [3-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 67 divergences: 100%|██████████| 5000/5000 [01:10<00:00, 71.24draws/s] 
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9524731568717033, but should be close to 0.8. Try to increase the number of tuning steps.
There were 65 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.012761889763310134, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(26/80) running inference on dataset #6/20 [3-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [02:52<00:00, 28.94draws/s]
The number of effective samples is smaller than 25% for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(27/80) running inference on dataset #7/20 [3-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [01:38<00:00, 50.98draws/s]
The acceptance probability does not match the target. It is 0.9293998718195831, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.929576171180873, but should be close to 0.8. Try to increase the number of tuning steps.
The number of effective samples is smaller than 25% for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(28/80) running inference on dataset #8/20 [3-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 5 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 566.83draws/s]
There were 4 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9032836826390075, but should be close to 0.8. Try to increase the number of tuning steps.
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9062689802862735, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(29/80) running inference on dataset #9/20 [3-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [01:10<00:00, 71.14draws/s]
The acceptance probability does not match the target. It is 0.8928460780747998, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.8908073782629071, but should be close to 0.8. Try to increase the number of tuning steps.
The number of effective samples is smaller than 25% for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(30/80) running inference on dataset #10/20 [3-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [02:13<00:00, 37.51draws/s]
The acceptance probability does not match the target. It is 0.890156482757511, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(31/80) running inference on dataset #11/20 [3-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 520.40draws/s] 
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(32/80) running inference on dataset #12/20 [3-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 549.73draws/s]
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(33/80) running inference on dataset #13/20 [3-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:11<00:00, 441.64draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(34/80) running inference on dataset #14/20 [3-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:10<00:00, 483.97draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(35/80) running inference on dataset #15/20 [3-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 537.25draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(36/80) running inference on dataset #16/20 [3-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 558.94draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(37/80) running inference on dataset #17/20 [3-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:10<00:00, 478.61draws/s]
The acceptance probability does not match the target. It is 0.8847580349865493, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(38/80) running inference on dataset #18/20 [3-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 535.41draws/s]
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(39/80) running inference on dataset #19/20 [3-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [01:05<00:00, 75.99draws/s]
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(40/80) running inference on dataset #20/20 [3-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 523.23draws/s]
running 4-peak model
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(41/80) running inference on dataset #1/20 [4-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 4 divergences: 100%|██████████| 5000/5000 [04:16<00:00, 19.52draws/s]
The acceptance probability does not match the target. It is 0.936205357437923, but should be close to 0.8. Try to increase the number of tuning steps.
There were 4 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9297828131027847, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(42/80) running inference on dataset #2/20 [4-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 855 divergences: 100%|██████████| 5000/5000 [06:27<00:00, 12.89draws/s]
There were 451 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6892331457340514, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 404 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.05 for some parameters. This indicates slight problems during sampling.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(43/80) running inference on dataset #3/20 [4-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1,251 divergences: 100%|██████████| 5000/5000 [07:26<00:00, 11.19draws/s]
There were 414 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 837 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.41667153600098267, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(44/80) running inference on dataset #4/20 [4-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 258 divergences: 100%|██████████| 5000/5000 [08:04<00:00, 10.31draws/s]
There were 95 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.89321739715486, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 162 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9369833420885747, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(45/80) running inference on dataset #5/20 [4-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1,101 divergences: 100%|██████████| 5000/5000 [05:28<00:00, 15.21draws/s]
There were 490 divergences after tuning. Increase `target_accept` or reparameterize.
There were 611 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(46/80) running inference on dataset #6/20 [4-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 548 divergences: 100%|██████████| 5000/5000 [08:24<00:00,  9.92draws/s]
There were 115 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 433 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(47/80) running inference on dataset #7/20 [4-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 514 divergences: 100%|██████████| 5000/5000 [06:39<00:00, 12.51draws/s]
There were 124 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9023351744343873, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 390 divergences after tuning. Increase `target_accept` or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(48/80) running inference on dataset #8/20 [4-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1 divergences: 100%|██████████| 5000/5000 [04:36<00:00, 18.07draws/s]
The acceptance probability does not match the target. It is 0.9873080738301657, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.9821223495061223, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(49/80) running inference on dataset #9/20 [4-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 915 divergences: 100%|██████████| 5000/5000 [05:51<00:00, 14.21draws/s] 
There were 915 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.4665887868329753, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The acceptance probability does not match the target. It is 0.9593271597053397, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(50/80) running inference on dataset #10/20 [4-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 5 divergences: 100%|██████████| 5000/5000 [08:26<00:00,  9.87draws/s]
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 4 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9552719042660363, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(51/80) running inference on dataset #11/20 [4-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:15<00:00, 313.24draws/s]
The acceptance probability does not match the target. It is 0.8864004916402762, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(52/80) running inference on dataset #12/20 [4-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:12<00:00, 398.21draws/s]
The acceptance probability does not match the target. It is 0.8864367492247963, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(53/80) running inference on dataset #13/20 [4-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1 divergences: 100%|██████████| 5000/5000 [00:12<00:00, 397.47draws/s]
The acceptance probability does not match the target. It is 0.8927876852083562, but should be close to 0.8. Try to increase the number of tuning steps.
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.8959262246360737, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(54/80) running inference on dataset #14/20 [4-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:13<00:00, 364.01draws/s]
The acceptance probability does not match the target. It is 0.9153072196805057, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.9088962177804752, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(55/80) running inference on dataset #15/20 [4-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 7 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 502.77draws/s]
There were 2 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.8877870842623247, but should be close to 0.8. Try to increase the number of tuning steps.
There were 5 divergences after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(56/80) running inference on dataset #16/20 [4-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:08<00:00, 580.76draws/s] 
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(57/80) running inference on dataset #17/20 [4-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:12<00:00, 393.01draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(58/80) running inference on dataset #18/20 [4-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1 divergences: 100%|██████████| 5000/5000 [00:10<00:00, 456.34draws/s]
The acceptance probability does not match the target. It is 0.8980388840600745, but should be close to 0.8. Try to increase the number of tuning steps.
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(59/80) running inference on dataset #19/20 [4-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1 divergences: 100%|██████████| 5000/5000 [00:56<00:00, 89.08draws/s] 
The acceptance probability does not match the target. It is 0.8900980320949415, but should be close to 0.8. Try to increase the number of tuning steps.
The number of effective samples is smaller than 25% for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(60/80) running inference on dataset #20/20 [4-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:09<00:00, 517.82draws/s]
running 5-peak model
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(61/80) running inference on dataset #1/20 [5-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 506 divergences: 100%|██████████| 5000/5000 [07:59<00:00, 10.43draws/s]
There were 194 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 312 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(62/80) running inference on dataset #2/20 [5-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 627 divergences: 100%|██████████| 5000/5000 [08:03<00:00, 10.35draws/s]
There were 317 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 309 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(63/80) running inference on dataset #3/20 [5-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 124 divergences: 100%|██████████| 5000/5000 [08:50<00:00,  9.42draws/s]
There were 117 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.7011247470819153, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 7 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(64/80) running inference on dataset #4/20 [5-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 555 divergences: 100%|██████████| 5000/5000 [08:00<00:00, 10.40draws/s]
There were 279 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 276 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(65/80) running inference on dataset #5/20 [5-peak model:2-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 858 divergences: 100%|██████████| 5000/5000 [08:07<00:00, 10.26draws/s]
There were 581 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6687705269695149, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 277 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(66/80) running inference on dataset #6/20 [5-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 2,122 divergences: 100%|██████████| 5000/5000 [06:37<00:00, 12.58draws/s] 
There were 1300 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.13764175918576582, but should be close to 0.8. Try to increase the number of tuning steps.
There were 821 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.4964831663497813, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(67/80) running inference on dataset #7/20 [5-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 560 divergences: 100%|██████████| 5000/5000 [07:58<00:00, 10.45draws/s]
There were 109 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 450 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.7121045010326953, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(68/80) running inference on dataset #8/20 [5-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 260 divergences: 100%|██████████| 5000/5000 [05:58<00:00, 13.95draws/s]
There were 139 divergences after tuning. Increase `target_accept` or reparameterize.
There were 121 divergences after tuning. Increase `target_accept` or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(69/80) running inference on dataset #9/20 [5-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 16 divergences: 100%|██████████| 5000/5000 [09:04<00:00,  9.18draws/s]
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 16 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.7025937591226383, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.05 for some parameters. This indicates slight problems during sampling.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(70/80) running inference on dataset #10/20 [5-peak model:3-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 344 divergences: 100%|██████████| 5000/5000 [08:41<00:00,  9.59draws/s]
There were 58 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 286 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.7084540704155302, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(71/80) running inference on dataset #11/20 [5-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1,699 divergences: 100%|██████████| 5000/5000 [01:18<00:00, 63.65draws/s] 
There were 1651 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.02200413827568289, but should be close to 0.8. Try to increase the number of tuning steps.
There were 48 divergences after tuning. Increase `target_accept` or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(72/80) running inference on dataset #12/20 [5-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 850 divergences: 100%|██████████| 5000/5000 [00:31<00:00, 158.47draws/s]
There were 168 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6209902936762827, but should be close to 0.8. Try to increase the number of tuning steps.
There were 682 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.40687738858303935, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(73/80) running inference on dataset #13/20 [5-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 46 divergences: 100%|██████████| 5000/5000 [04:43<00:00, 17.64draws/s]
There were 24 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9507858834299686, but should be close to 0.8. Try to increase the number of tuning steps.
There were 22 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9534240491888107, but should be close to 0.8. Try to increase the number of tuning steps.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(74/80) running inference on dataset #14/20 [5-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 1,693 divergences: 100%|██████████| 5000/5000 [02:24<00:00, 34.63draws/s] 
There were 1057 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.34898466174284565, but should be close to 0.8. Try to increase the number of tuning steps.
There were 636 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.16318393977037837, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(75/80) running inference on dataset #15/20 [5-peak model:4-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 718 divergences: 100%|██████████| 5000/5000 [07:02<00:00, 11.82draws/s]
There were 356 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
There were 362 divergences after tuning. Increase `target_accept` or reparameterize.
The chain reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(76/80) running inference on dataset #16/20 [5-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:10<00:00, 490.40draws/s]
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(77/80) running inference on dataset #17/20 [5-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [00:16<00:00, 298.15draws/s]
The acceptance probability does not match the target. It is 0.9093298971212235, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(78/80) running inference on dataset #18/20 [5-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 18 divergences: 100%|██████████| 5000/5000 [02:42<00:00, 30.71draws/s]
There were 17 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.8971289236422962, but should be close to 0.8. Try to increase the number of tuning steps.
There was 1 divergence after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.9800008753911829, but should be close to 0.8. Try to increase the number of tuning steps.
The rhat statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(79/80) running inference on dataset #19/20 [5-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 0 divergences: 100%|██████████| 5000/5000 [01:09<00:00, 71.47draws/s]
The acceptance probability does not match the target. It is 0.895843982770825, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.9141303863934854, but should be close to 0.8. Try to increase the number of tuning steps.
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
(80/80) running inference on dataset #20/20 [5-peak model:5-peak spectrum]
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [epsilon, sigma_e, sigma, mu, amp]
Sampling 2 chains, 11 divergences: 100%|██████████| 5000/5000 [00:10<00:00, 460.32draws/s]
There were 5 divergences after tuning. Increase `target_accept` or reparameterize.
There were 6 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.8849089207533496, but should be close to 0.8. Try to increase the number of tuning steps.

Model visualization

In [11]:
pm.model_to_graphviz(models[0])
Out[11]:
%3 cluster1 x 2 1 x 2 cluster100 100 cluster15 x 100 15 x 100 mu mu ~ Uniform y y ~ Deterministic mu->y sigma sigma ~ Lognormal sigma->y amp amp ~ Uniform amp->y y_pred y_pred ~ Normal y->y_pred epsilon epsilon ~ HalfNormal epsilon->y_pred sigma_e sigma_e ~ Gamma sigma_e->epsilon
In [12]:
# save model figure as image
img = pm.model_to_graphviz(models[0])
img.render(filename=file_basename + '_model', format='png');

Collect results and save

In [13]:
# posterior predictive traces
ppc = [pm.sample_posterior_predictive(traces[i], samples=500, model=models[i]) for i in range(len(traces))]
/home/ppsda/venv/ppsda/lib/python3.6/site-packages/pymc3/sampling.py:1247: UserWarning: samples parameter is smaller than nchains times ndraws, some draws and/or chains may not be represented in the returned posterior predictive sample
  "samples parameter is smaller than nchains times ndraws, some draws "
100%|██████████| 500/500 [00:00<00:00, 607.37it/s]
/home/ppsda/venv/ppsda/lib/python3.6/site-packages/pymc3/sampling.py:1247: UserWarning: samples parameter is smaller than nchains times ndraws, some draws and/or chains may not be represented in the returned posterior predictive sample
  "samples parameter is smaller than nchains times ndraws, some draws "
100%|██████████| 500/500 [00:00<00:00, 617.12it/s]
100%|██████████| 500/500 [00:00<00:00, 644.90it/s]
100%|██████████| 500/500 [00:00<00:00, 654.75it/s]
100%|██████████| 500/500 [00:00<00:00, 655.63it/s]
100%|██████████| 500/500 [00:00<00:00, 646.15it/s]
100%|██████████| 500/500 [00:00<00:00, 629.37it/s]
100%|██████████| 500/500 [00:00<00:00, 628.87it/s]
100%|██████████| 500/500 [00:00<00:00, 646.42it/s]
100%|██████████| 500/500 [00:00<00:00, 635.23it/s]
100%|██████████| 500/500 [00:00<00:00, 643.78it/s]
100%|██████████| 500/500 [00:00<00:00, 640.49it/s]
100%|██████████| 500/500 [00:00<00:00, 611.90it/s]
100%|██████████| 500/500 [00:00<00:00, 658.50it/s]
100%|██████████| 500/500 [00:00<00:00, 652.58it/s]
100%|██████████| 500/500 [00:00<00:00, 611.34it/s]
100%|██████████| 500/500 [00:00<00:00, 610.21it/s]
100%|██████████| 500/500 [00:00<00:00, 607.98it/s]
100%|██████████| 500/500 [00:00<00:00, 606.77it/s]
100%|██████████| 500/500 [00:00<00:00, 617.20it/s]
100%|██████████| 500/500 [00:00<00:00, 612.75it/s]
100%|██████████| 500/500 [00:00<00:00, 620.25it/s]
100%|██████████| 500/500 [00:00<00:00, 598.95it/s]
100%|██████████| 500/500 [00:00<00:00, 642.54it/s]
100%|██████████| 500/500 [00:00<00:00, 632.02it/s]
100%|██████████| 500/500 [00:00<00:00, 640.30it/s]
100%|██████████| 500/500 [00:00<00:00, 638.75it/s]
100%|██████████| 500/500 [00:00<00:00, 650.96it/s]
100%|██████████| 500/500 [00:00<00:00, 640.60it/s]
100%|██████████| 500/500 [00:00<00:00, 633.66it/s]
100%|██████████| 500/500 [00:00<00:00, 626.24it/s]
100%|██████████| 500/500 [00:00<00:00, 645.41it/s]
100%|██████████| 500/500 [00:00<00:00, 638.55it/s]
100%|██████████| 500/500 [00:00<00:00, 619.45it/s]
100%|██████████| 500/500 [00:00<00:00, 631.51it/s]
100%|██████████| 500/500 [00:00<00:00, 657.02it/s]
100%|██████████| 500/500 [00:00<00:00, 657.37it/s]
100%|██████████| 500/500 [00:00<00:00, 638.70it/s]
100%|██████████| 500/500 [00:00<00:00, 653.17it/s]
100%|██████████| 500/500 [00:00<00:00, 661.85it/s]
100%|██████████| 500/500 [00:00<00:00, 649.33it/s]
100%|██████████| 500/500 [00:00<00:00, 668.29it/s]
100%|██████████| 500/500 [00:02<00:00, 215.52it/s]
100%|██████████| 500/500 [00:00<00:00, 635.08it/s]
100%|██████████| 500/500 [00:00<00:00, 647.40it/s]
100%|██████████| 500/500 [00:00<00:00, 614.83it/s]
100%|██████████| 500/500 [00:00<00:00, 634.33it/s]
100%|██████████| 500/500 [00:00<00:00, 640.77it/s]
100%|██████████| 500/500 [00:00<00:00, 620.06it/s]
100%|██████████| 500/500 [00:00<00:00, 624.71it/s]
100%|██████████| 500/500 [00:00<00:00, 643.39it/s]
100%|██████████| 500/500 [00:00<00:00, 639.42it/s]
100%|██████████| 500/500 [00:00<00:00, 601.97it/s]
100%|██████████| 500/500 [00:00<00:00, 574.17it/s]
100%|██████████| 500/500 [00:00<00:00, 574.64it/s]
100%|██████████| 500/500 [00:00<00:00, 585.50it/s]
100%|██████████| 500/500 [00:00<00:00, 622.27it/s]
100%|██████████| 500/500 [00:00<00:00, 629.65it/s]
100%|██████████| 500/500 [00:00<00:00, 616.05it/s]
100%|██████████| 500/500 [00:00<00:00, 646.31it/s]
100%|██████████| 500/500 [00:00<00:00, 642.43it/s]
100%|██████████| 500/500 [00:00<00:00, 640.42it/s]
100%|██████████| 500/500 [00:00<00:00, 631.34it/s]
100%|██████████| 500/500 [00:00<00:00, 649.08it/s]
100%|██████████| 500/500 [00:00<00:00, 634.08it/s]
100%|██████████| 500/500 [00:00<00:00, 648.39it/s]
100%|██████████| 500/500 [00:00<00:00, 644.18it/s]
100%|██████████| 500/500 [00:00<00:00, 633.49it/s]
100%|██████████| 500/500 [00:00<00:00, 639.27it/s]
100%|██████████| 500/500 [00:00<00:00, 643.54it/s]
100%|██████████| 500/500 [00:00<00:00, 638.41it/s]
100%|██████████| 500/500 [00:00<00:00, 629.66it/s]
100%|██████████| 500/500 [00:00<00:00, 639.15it/s]
100%|██████████| 500/500 [00:00<00:00, 633.78it/s]
100%|██████████| 500/500 [00:00<00:00, 638.00it/s]
100%|██████████| 500/500 [00:00<00:00, 644.97it/s]
100%|██████████| 500/500 [00:00<00:00, 620.07it/s]
100%|██████████| 500/500 [00:00<00:00, 649.72it/s]
100%|██████████| 500/500 [00:00<00:00, 635.05it/s]
100%|██████████| 500/500 [00:00<00:00, 626.85it/s]
In [14]:
# various plots to inspect the inference results
varnames = ['amp', 'mu', 'sigma', 'epsilon']

#az.plot_trace(traces[2], varnames, compact=True);
#az.plot_trace(traces[2], varnames, divergences='top');
#az.plot_autocorr(traces[0], varnames);
#az.plot_posterior(traces[2], varnames);

#for idx, trace in enumerate(traces):
#    az.plot_forest(trace, var_names = varnames, r_hat=True, ess=True);
In [15]:
if conf['model_mode'] == 'train':
    # collect the results and display
    df = res.get_results_summary(varnames, traces, ppc, y_val, epsilon_real=0.05, sets=tsets, labels=lmodpeak)
else:
    # load results from disk
    df = pd.read_csv(file_basename + '.csv')
    df.index += 1
#df.sort_values(by=['r2'])
df
/home/ppsda/venv/ppsda/lib/python3.6/site-packages/arviz/stats/stats.py:1196: UserWarning: For one or more samples the posterior variance of the log predictive densities exceeds 0.4. This could be indication of WAIC starting to fail. 
See http://arxiv.org/abs/1507.04544 for details
  "For one or more samples the posterior variance of the log predictive "
Out[15]:
r_hat mcse ess bfmi r2 waic epsilon epsilon_real model peaks
1 1.00 0.000000 3929.428571 0.954804 0.999680 -4754.801510 0.049517 0.05 2 2
2 1.00 0.000000 5300.714286 1.049510 0.999554 -3950.540267 0.064688 0.05 2 2
3 1.00 0.000000 4278.571429 1.091909 0.999392 -3785.784443 0.068167 0.05 2 2
4 1.00 0.000000 3959.000000 1.051070 0.999846 -4684.131350 0.050658 0.05 2 2
5 1.00 0.000000 4824.000000 1.133247 0.999518 -3341.513910 0.078943 0.05 2 2
... ... ... ... ... ... ... ... ... ... ...
76 1.00 0.000188 5131.875000 1.042221 0.998972 -991.914686 0.172256 0.05 5 5
77 1.00 0.000000 4314.812500 1.083740 0.999893 -4150.327292 0.060371 0.05 5 5
78 1.31 4.493625 2291.062500 0.988276 0.999798 -2840.819256 0.093411 0.05 5 5
79 1.00 0.000687 2866.500000 1.019639 0.999941 -4682.102306 0.050504 0.05 5 5
80 1.00 0.000000 4706.750000 1.049787 0.999884 -4730.307148 0.049733 0.05 5 5

80 rows × 10 columns

In [16]:
if conf['model_mode'] == 'train':
    # save results to .csv
    df.to_csv(file_basename + '.csv', index=False)

Plot posterior

In [17]:
fig.plot_posterior(x_val, ldata, traces, ppc, dims=(int(truns/2),2), figure_size=(12,int(truns*(1.8))),
                       savefig='yes', fname=file_basename, showpeaks='no', sets=tsets)
In [18]:
fig.plot_posterior(x_val, ldata, traces, ppc, dims=(int(truns/2),2), figure_size=(12,int(truns*(1.8))),
                       savefig='yes', fname=file_basename, showpeaks='yes', sets=tsets)
In [19]:
cnf.close(out_path)